
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 2
 * @Author : WangRuoyu 
 * @Date : 2023/5/12 16:22
 */

#include "iostream"
#include "cstring"
#include "algorithm"

using namespace std;

int main() {
    int m, n;
    cin >> m >> n;
    int nums[m][n];
    bool st[m][n];
    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> nums[i][j];
            st[i][j] = false;
        }
    }

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n - 2; ++j) {
            if (nums[i][j] == nums[i][j + 1] && nums[i][j] == nums[i][j + 2]) {
                st[i][j] = true;
                st[i][j + 1] = true;
                st[i][j + 2] = true;
            }
        }
    }

    for (int j = 0; j < n; ++j) {
        for (int i = 0; i < m - 2; ++i) {
            if (nums[i][j] == nums[i + 1][j] && nums[i][j] == nums[i + 2][j]) {
                st[i][j] = true;
                st[i + 1][j] = true;
                st[i + 2][j] = true;
            }
        }
    }

    for (int i = 0; i < m; ++i) {
        for (int j = 0; j < n; ++j) {
            if (st[i][j]) {
                cout << "0 ";
            } else {
                cout << nums[i][j] << " ";
            }
        }
        cout << endl;
    }

    return 0;
}